package com.bjpowernode.web;

import com.bjpowernode.entity.dto.ChartValueNameData;
import com.bjpowernode.entity.dto.OverviewData;
import com.bjpowernode.result.R;
import com.bjpowernode.service.StatisticService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 统计信息controller
 */
@RestController
@Slf4j
@RequestMapping("/api/statistics")
public class StatisticsController {

    @Resource
    private StatisticService statisticService;

    @GetMapping("overview")
    public R loadOverviewInfo() {
        OverviewData overviewData = statisticService.getOverViewData();
        return R.OK(overviewData);
    }

    /*
              { value: 100, name: '线索' },
              { value: 80, name: '客户' },
              { value: 60, name: '订单' },
              { value: 40, name: '成交'}
     */
    @GetMapping("funnel")
    public R loadFunnelData() {
        log.info("加载漏斗图数据");
        List<ChartValueNameData> chartValueNameDataList = statisticService.loadFunnelData();
        return R.OK(chartValueNameDataList);
    }

    @GetMapping("pie")
    public R loadPieData() {
        log.info("加载饼图数据");
        List<ChartValueNameData> chartValueNameDataList = statisticService.loadPieData();
        return R.OK(chartValueNameDataList);
    }

    @GetMapping("bar")
    public R loadBarData() {
        log.info("加载柱状图数据");
        Integer[] barDataArr = statisticService.loadBarData();
        return R.OK(barDataArr);
    }
}
